From 9d4e596c9c1125962b8d2b392c0cbd1046665006 Mon Sep 17 00:00:00 2001 From: Jonathan Dieter Date: Fri, 22 Jun 2018 14:04:41 +0300 Subject: [PATCH] Add support for --stdout to unzck Signed-off-by: Jonathan Dieter --- src/unzck.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/unzck.c b/src/unzck.c index 816c0dc..ff8f2db 100644 --- a/src/unzck.c +++ b/src/unzck.c @@ -45,6 +45,7 @@ static struct argp_option options[] = { {"verbose", 'v', 0, 0, "Increase verbosity (can be specified more than once for debugging)"}, {"quiet", 'q', 0, 0, "Only show errors"}, + {"stdout", 'c', 0, 0, "Direct output to stdout"}, {"version", 'V', 0, 0, "Show program version"}, { 0 } }; @@ -52,6 +53,7 @@ static struct argp_option options[] = { struct arguments { char *args[1]; zck_log_type log_level; + int stdout; }; static error_t parse_opt (int key, char *arg, struct argp_state *state) { @@ -66,6 +68,9 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { case 'q': arguments->log_level = ZCK_LOG_ERROR; break; + case 'c': + arguments->stdout = 1; + break; case 'V': version(); break; @@ -114,12 +119,15 @@ int main (int argc, char *argv[]) { char *out_name = malloc(strlen(arguments.args[0]) - 3); snprintf(out_name, strlen(arguments.args[0]) - 3, "%s", arguments.args[0]); - int dst_fd = open(out_name, O_TRUNC | O_WRONLY | O_CREAT, 0644); - if(dst_fd < 0) { - printf("Unable to open %s", out_name); - perror(""); - free(out_name); - exit(1); + int dst_fd = STDOUT_FILENO; + if(!arguments.stdout) { + dst_fd = open(out_name, O_TRUNC | O_WRONLY | O_CREAT, 0644); + if(dst_fd < 0) { + printf("Unable to open %s", out_name); + perror(""); + free(out_name); + exit(1); + } } int good_exit = False; -- 2.30.2